package org.ribizli.basicgameserver;

import java.util.Map;
import java.util.UUID;
import org.json.JSONObject;

public abstract class Game {

  public static final String ERROR_USER_ALREADY_REGISTERED = "USER_ALREADY_REGISTERED";
  public static final String ERROR_USER_NOT_REGISTERED = "USER_NOT_REGISTERED";
  public static final String ERROR_USER_NOT_LOGGED = "USER_NOT_LOGGED";
  public static final String ERROR_WRONG_PASSWORD = "WRONG_PASSWORD";
  
  public void init() {

  }

  public abstract String getID();

  public abstract JSONObject messages(String token, JSONObject messages) throws GameException;
  
  public abstract void register(String username, String password, Map<String, String> details) throws GameException;
  
  public abstract JSONObject getTopScores(String user) throws GameException;

  
  /**
   * 
   * @param username
   * @param password
   * @param info - Information returned to the client. Put an empty JSONObject
   * object which can be filled by the Game with additional info.
   * @return The token which can be used for the further messages to authenticate 
   * client
   * @throws GameException
   */
  public abstract String newPlayer(String username, String password, JSONObject info)
      throws GameException;

  public abstract void playerLeft(String token);
  
  public static String getRandomToken() {
  	return UUID.randomUUID().toString();
  }
}
